//------------------------------------------------------------------------------
// <copyright file="AuthorNameValidation.cs" company="Damian Antonowicz">
//       copyright © 2010 Damian Antonowicz
// </copyright>
// <author>Damian Antonowicz</author>
// <email>poczta@damianantonowicz.pl</email>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using DotBeer.Business.Entities;

namespace DotBeer.UI.WPFClient
{
    public class AuthorNameValidation : ValidationRule
    {
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            NameValidation nameVal = new NameValidation();
            ValidationResult result = nameVal.Validate(value, cultureInfo);

            if (!result.IsValid)
                return result;
            else
            {
                Authors authors = Authors.Instance;

                if (authors.SingleOrDefault(a => a.ToUpper() == value.ToString().ToUpper()) != null)
                    return new ValidationResult(false, "Provided author name already exists. Please enter different author name");
            }

            return new ValidationResult(true, null);
        }
    }
}
